﻿using System.Web.Security;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using RLAWEB.Models;
using RLAWEB.RLAServiceReference;

namespace RLAWEB.Account
{
    public partial class Register : Page
    {
        protected void CreateUser_Click(object sender, EventArgs e)
        {

            RealLifeServiceClient client = new RealLifeServiceClient();
            var user = new User(){
                                    Email = txtMail.Text,
                                    CurrentStatus = RLAServiceReference.User.Status.Active,
                                    Password = Password.Text,
                                    ProfileName = UserName.Text,
                                    FirstName = txtFName.Text,
                                    LastName = txtLName.Text,
                                    Gender = rdSex.SelectedValue[0]
                                };
            if (client.CreateUser(user) > 0)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                ErrorMessage.Text = "Something went wrong..";
            }

            /*
             * var manager = new UserManager();
            var user = new ApplicationUser() { UserName = UserName.Text, User = new User(){ProfileName = UserName.Text, Password = Password.Text} };
            
            IdentityResult result = manager.Create(user, Password.Text);
            if (result.Succeeded)
            {
                IdentityHelper.SignIn(manager, user, isPersistent: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else 
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
             */
        }
    }
}